<%= form_for(@exercise_rating) do |f| %>
    <% if @exercise_rating.errors.any? %>
        <div id="error_explanation">
          <h2><%= pluralize(@exercise_rating.errors.count, "error") %> prohibited this exercise_rating from being saved:</h2>

          <ul>
            <% @exercise_rating.errors.full_messages.each do |msg| %>
                <li><%= msg %></li>
            <% end %>
          </ul>
        </div>
    <% end %>
    <p> Please enter project rating for lecture <br /> <b><%= Lecture.find(params[:lecture_id]).title %>. </b></p>
    <div class="hiddenField">
      <%= f.label :id %><br />
      <%= f.text_field :id %>
    </div>
    <div class="hiddenField" class="field">
      <%= f.label :lecture_id %><br />
      <%= f.number_field :lecture_id , :value => params[:lecture_id]  %>
    </div>
    <div class="hiddenField" class="field">
      <%= f.label :user_id %><br />
      <%= f.number_field :user_id, :value => current_user.id %>
    </div>

    <p>
      <% (0..4).each do |i| %>
          <% if i == 0 then %>
              <%= image_tag("star.png", :alt => "star", :width => "30", :class => "starRating", :id => i.to_s) %>
          <% else %>
              <%= image_tag("starEmpty.png", :alt => "starEmpty", :width => "30", :class => "starRating", :id => i.to_s) %>
          <% end %>
      <% end %>
    </p>

    <div class="field">
      Difficulty:
      <select id="exercise_rating_difficulty" name="exercise_rating[difficulty]">
        <option value="" selected="selected">Please project difficulty</option>
        <option value="1">1</option>
        <option value="2">2</option>
        <option value="3">3</option>
        <option value="4">4</option>
        <option value="5">5</option>
      </select>
    </div>

    <div class="field">
      Work Load:
      <select id="exercise" name="exercise_rating[work_load]" type="number">
        <option value="" selected="selected">Select project work load</option>
        <option value="1">1</option>
        <option value="2">2</option>
        <option value="3">3</option>
        <option value="4">4</option>
        <option value="5">5</option>
      </select>
    </div>
    <div class="hiddenField">
      <%= f.label :rating, "Rating: (1-5)" %><br />
      <%= f.number_field :rating %>
    </div>
    <div class="field">
      <%= f.label :comment %><br />
      <%= f.text_field :comment %>
    </div>
    <div class="actions">
      <%= f.submit "Save my rating", :class => "shinyButton" %>
    </div>
<% end %>

<script>
    var $jQuery = jQuery.noConflict();
    $jQuery(".starRating").mouseenter(function() {
        //alert("On Star with ID: " + this.id);
        var rating = 1;
        var srcFull = "../../assets/star.png";
        var srcEmpty = "../../assets/starEmpty.png";
        for (var i = 0; i < 5; i++){
            var currentElement = ".starRating#" + i;
            if (i <= this.id){
                $jQuery(currentElement).attr("src",srcFull);
            }
            else{
                $jQuery(currentElement).attr("src",srcEmpty);
            }
            $jQuery("#exercise_rating_rating").val(parseInt(this.id)+1);
        }
    });
</script>